{extend name="index/nav" /}}
{block name="main"}
<link rel="stylesheet" href="/static/adminLogin/js/summernote-master/dist/summernote-lite.css">
<script src="/static/adminLogin/js/summernote-master/dist/jquery-1.11.0.min.js"></script>
<div class="body">
    <div class="">
        <h2>添加资讯</h2>
    </div>
    <div class="">
        <form action="{:url('admin/index/toNewsAdd')}" class="am-form am-form-horizontal" role="form" enctype="multipart/form-data" method="post">
            <div class="">
                <label for="doc-ipt-1" class="">上传图片</label>
                <div class="">
                    <input type="file" id="doc-ipt-1"name="image[]" multiple="multiple" >
                    <div class="img-show" style="display: none">
                        <!--<span>图片预览</span>-->
                        <span class="image-width">
                        </span>
                    </div>
                </div>
            </div>
            <div class="">
                <label for="doc-ipt-2" class="">添加标题</label>
                <div class="">
                    <input type="text" id="doc-ipt-2"name="title">
                </div>
            </div>
            <div class="">
                <label for="" class="">添加简介</label>
                <div class="">
                    <textarea class="summernote " name="introduce"></textarea>
                </div>
            </div>
            <div class="">
                <label for="" class="">添加内容</label>
                <div class="">
                    <textarea class="summernote " id='summernote'name="content"></textarea>
                </div>
            </div>
            <div class="">
                <label for="grade" class="">选择等级</label>
                <div class="">
                    <select name="grade" id="grade">
                        <option value="1">强烈推荐</option>
                        <option value="2">图文资讯</option>
                        <option value="3">热点资讯</option>
                        <option value="4">普通资讯</option>
                    </select>
                </div>
            </div>
            <div class="">
                <button type="submit" class="btn-default">提交</button>
            </div>
        </form>
    </div>
</div>

<script src="/static/adminLogin/js/summernote-master/dist/summernote-lite.js"></script>
<script src="/static/adminLogin/js/summernote-master/lang/summernote-zh-CN.js"></script>
<script>
    $('#summernote').each(function() {
        var $this=$(this);
        $this.summernote({
            height: 300,
            tabsize: 2,
            lang:'zh-CN',
            callbacks: {
                onImageUpload: function(files) {
                    var size = files[0].size;
                    if((size / 1024 / 1024) > 4) {
                        alert("图片大小不能超过4M...");
                        return false;
                    }

                    var files = files[0];
                    var data = new FormData();
                    data.append('file',files);

                    $.ajax({
                        data : data,
                        type : "POST",
                        url : "{:url('admin/index/edit')}", // 图片上传出来的url，返回的是图片上传后的路径，http格式
                        cache : false,
                        contentType : false,
                        processData : false,
                        dataType : "json",
                        success: function(data) { //data是返回的hash,key之类的值，key是定义的文件名
                            data=JSON.parse(data);
                            $this.summernote('insertImage', data, function($image) {
                           });
                        },
                        error:function(){
                            alert("上传失败");
                        }
                    });
                }
            }
        })
    })
    $('#collapse-nav2').addClass('am-in');
</script>
{/block}